// pages/orderInfo/orderInfo.js
// 获取应用实例
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    currentTab:1,
    list:[],
    onOpen:false,
    onevaluation:false,
    csorderno:'',
    unsubscribenum:'', //退订规则
  },
  /* 小程序1.0版本
   * 选择店铺后返回上一级
   */
  navigateBack() {
    wx.navigateBack({
      delta: 2
    })
  },
  //获取订单列表
  switchNav(e){
    let _this = this
    let current = e.currentTarget.dataset.current

    let status = current
    if(current==5){
      status=4
    }
    let token = wx.getStorageSync('token')
    wx.request({
      url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
      data: {
       //请求后台的分页数据
       cmd:'GetOrderList',
       token:token,
       status:status
      },
      method: "get",
      success(res) {
        var data = res.data.DATA;
        console.log(data);
        if(res.data.STATUS=='Error'){
          wx.navigateTo({
            url: '../login/login',
          })
       }else{
        _this.setData({
          list:data,
          currentTab:current
        })
       }
     

      }
   })
   
  },
//取消订单
oncancel(e){
  let that = this;
  let orderno = e.currentTarget.dataset.orderno;
  let csorderno = that.data.csorderno;
     // 页面被展示
     let roomid=e.currentTarget.dataset.roomid   //传入roomid
     wx.request({
       url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
       data: {
        //请求后台的分页数据
        cmd:'getRoomInfo',
        RoomID:roomid,
       },
       method: "get",
       success(res) {
             that.setData({
              unsubscribenum:res.data.DATA.CancelRule,
              csorderno:orderno,
              onOpen:true
             })
       }
     });

},
//评价
onevaluation(e){
  let that = this;
  let orderno = e.currentTarget.dataset.orderno;
  let csorderno = that.data.csorderno;
  that.setData({
    csorderno:orderno,
    onevaluation:true
  })
},
    // 拨打电话
    ontel(e){
      let that = this
      let  token=  wx.getStorageSync('token')
      wx.request({
        url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
        data: {
          cmd: 'aboutme',
          token:token
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success (data) {
          console.log(data.data.DATA)
          wx.makePhoneCall({
            phoneNumber: data.data.DATA.Mobile,
          })
        }
      });
    },
  //订单详情
  oporderinfodeta(e) {  
    let OrderNo = e.currentTarget.dataset.orderno
    let _this = this
    if(_this.data.currentTab==2){
      let url = "../Invitationandsharing/Invitationandsharing?OrderNo="+OrderNo
      wx.navigateTo({url: url})
    }
    if(_this.data.currentTab==1){
      let url = "../orderInfo/orderinfodetail?OrderNo="+OrderNo
      wx.navigateTo({url: url})
    }
    if(_this.data.currentTab==5){
      let url = "../details/details?OrderNo="+OrderNo
      wx.navigateTo({url: url})
    }
    if(_this.data.currentTab==4){
      let url = "../details/details?OrderNo="+OrderNo
      wx.navigateTo({url: url})
    }
    if(_this.data.currentTab==3){
      let url = "../details/details?OrderNo="+OrderNo
      wx.navigateTo({url: url})
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let _this = this
    wx.hideTabBar() //隐藏系统tabbar
    app.editTabbar(); // 全局方法：editTabbar()调用自定义组件底部导航栏
    let token = wx.getStorageSync('token')
    wx.request({
      url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
      data: {
       //请求后台的分页数据
       cmd:'GetOrderList',
       token:token,
       status:1
      },
      method: "get",
      success(res) {
       var data = res.data.DATA;
       if( res.data.STATUS=='Error'){
          wx.navigateTo({
            url: '../login/login',
          })
       }else{
          _this.setData({
            list:data,
            currentTab:1
          })
       }
      }
   })
   let  userInfo =  wx.getStorageSync('userInfo')
   if(userInfo){
  console.log(userInfo)
   }else{
    wx.navigateTo({
      url: '../login/login',
    })
  }
  },
  onShow(e){
    let  userInfo=  wx.getStorageSync('userInfo')
    let that = this
    that.onLoad();
    if(userInfo){
      console.log(111)
    }else{
      wx.navigateTo({
        url: '../login/login',
      })
    }
    },
    //待支付取消订单
    dzfnok(e){
      let OrderNo=  e.currentTarget.dataset.orderno
      let that = this
      let token = wx.getStorageSync('token')
      wx.request({
        url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
        data: {
         //请求后台的分页数据
         cmd:'CancelOrder',
         token:token,
         OrderNo:OrderNo,
         Cause:'待支付取消订单'
        },
        method: "get",
        success(res) {
          console.log(res)
        if(res.data.STATUS=='Success'){
          wx.showToast({
            title: res.data.DESC,
            icon: 'success',
            duration: 2000
          })
          //刷新界面
          wx.request({
            url: 'https://www.yulonging.com/dwweb/wxapi.ashx',
            data: {
             //请求后台的分页数据
             cmd:'GetOrderList',
             token:token,
             status:1
            },
            method: "get",
            success(res) {
             var data = res.data.DATA;
             console.log(data);
             that.setData({
              list:data,
              currentTab:1
            })
            }
         })
        }else{
          wx.showToast({
            title: res.data.DESC,
            icon: 'error',
            duration: 2000
          })
        }  
        }
     })
    },
    


    //取消订单
    geturlnopay(e){
      wx.navigateTo({
        url: '../login/login',
      })
    },

    //支付跳转列表页
    geturlpay(e){
      let OrderNo=  e.currentTarget.dataset.orderno
      wx.navigateTo({
        url: '../orderInfo/orderinfodetail?OrderNo='+OrderNo,
      })
    },


    //邀请参会跳转
    geturladduser(e){
      console.log(e)
      wx.navigateTo({
        url: '../Invitationandsharing/Invitationandsharing?OrderNo='+e.currentTarget.dataset.orderno,
      })
    },

    // //评论跳转
    // geturlplun(e){
    //   wx.navigateTo({
    //     url: '../login/login',
    //   })
    // },


    //开发票跳转
    openinvoice(e){
      wx.navigateTo({
        url: '../controlInvoices/controlInvoices',
      })
    },
    
})